package com.beici;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.FileWriter;
import java.io.IOException;

/**
 * @auther WaterGhost
 * @date 2022/3/27 17:17
 */
public class wenan {
    static  int i = 84;
    public static void main(String[] args) throws IOException, InterruptedException {
        Connection connect = Jsoup.connect("https://www.wenanwang.com/zt/aiqing/");
        Document document = connect.get();
        Element select = document.select(".clearfix").get(0);
        Element newslist = select.select(".newslist").get(0);
        Elements li = newslist.getElementsByTag("li");
        for (Element element : li) {
            Thread.sleep(2000);
            Element a = element.getElementsByTag("a").get(0);
            String url = "https://www.wenanwang.com"+a.attr("href");
            down(url,"C:\\Users\\白\\Desktop\\WGHP(1)\\wenan\\"+i+".txt");
            i++;
        }
    }

    public static void down(String url,String path){
        Connection connect = Jsoup.connect(url);
        Document document = null;
        try {
            document = connect.get();
            Element select = document.select(".newsview").get(0);
            Element element = select.select(".content").get(0);
            FileWriter fileWriter = new FileWriter(path);
            fileWriter.write(element.toString());
            fileWriter.flush();
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
